package com.gqzdev.config;

import com.gqzdev.bean.Cat;
import com.gqzdev.bean.Department;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author tanghailan
 * @create 2021年09月01日 22:11
 */
@Configuration
//@Import({MainConfig.MyImportRegistrar.class})
@ComponentScan("com.gqzdev")
public class MainConfig {

	//@Bean
	public Department department() {
		Department department = new Department();
		department.setName("技术部");
		return department;
	}

	/**
	 * BeanDefinitionRegistry:Bean 定义信息的注册中心：图纸中心 它里面都是 BeanDefinition
	 * <bean id="department" class="com.gqzdev.bean.Department">
	 * <property name="name" value="技术部"/>
	 * </bean>
	 * 对应一个 BeanDefinition
	 */
	static class MyImportRegistrar implements ImportBeanDefinitionRegistrar {

		@Override
		public void registerBeanDefinitions(
				AnnotationMetadata importingClassMetadata,
				BeanDefinitionRegistry registry) {
			//BeanDefinition
			RootBeanDefinition catBeanDefinition = new RootBeanDefinition();
			catBeanDefinition.setBeanClass(Cat.class);
			//可以声明定义信息，包括我需要自动装配什么？
			registry.registerBeanDefinition("tomCat", catBeanDefinition);
		}
	}

}
